package com.yuan.service.fetchStrategy.baidu;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

import org.apache.log4j.Logger;

import com.yuan.goods.Goods;
import com.yuan.service.fetchStrategy.FetchStrategy;

public class BaiduAPIFetchStrategy implements FetchStrategy {

	private static final Logger logger = Logger.getLogger(BaiduAPIFetchStrategy.class);

	public List<Goods> run(String url) {

		JAXBContext jaxbContext;
		try {
			jaxbContext = JAXBContext.newInstance(BaiduAPIBO.class);

			Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();

			InputStreamReader reader = new InputStreamReader(new URL(url).openStream(), "utf-8");
			BaiduAPIBO baiduAPIXQuery = (BaiduAPIBO) unmarshaller.unmarshal(reader);

		} catch (JAXBException e) {
			logger.error("BaiduAPIFetchStrategy", e);
		} catch (UnsupportedEncodingException e) {
			logger.error("BaiduAPIFetchStrategy", e);
		} catch (MalformedURLException e) {
			logger.error("BaiduAPIFetchStrategy", e);
		} catch (IOException e) {
			logger.error("BaiduAPIFetchStrategy", e);
		}
		return null;
	}

}
